@extends('admin.layout')
@section('content')
    
    <div class="layui-card">
        <div class="layui-card-header">
            <form  class="layui-form" >
                <div class="layui-form-item">
                    <div class="layui-input-inline">
                        <input type="text" name="post_title" value="" autocomplete="off" placeholder="请输入标题" class="layui-input"/>
                    </div>
                    <div class="layui-input-inline">
                        <select name="category_id" >
                            <option value="">全部分类</option>
                            @foreach($categorys as $key =>$val)
                                <option value="{{$val['id']}}" @if(isset($checkArr) && in_array($val['id'],$checkArr)) selected @endif>{{$val['cat_name']}}</option>
                            @endforeach
                        </select>

                    </div>

                    <div class="layui-input-inline" style="width: 50px;">
                        <button class="layui-btn layui-btn-primary " lay-submit lay-filter="search"><i class="fa fa-search"></i></button>
                    </div>
                </div>
            </form>
            <div class="layui-btn-group layui-left-menu">
                {{--<a  href="{{route('admin.posts.create')}}" class="layui-btn"><i class="fa fa-plus-circle"></i>--}} 添加文章</a>
                <a  href="{{route('admin.posts.restore')}}" class="layui-btn layui-btn-danger ajax-batch-del"><i class="fa fa-trash-o"></i> 批量恢复</a>

            </div>
        </div>
        <div class="layui-card-body">
            <table id="dataTable" lay-filter="dataTable"></table>
            <script type="text/html" id="options">
                <div class="layui-btn-group">
                    {{--<a class="layui-btn layui-btn-sm " href="/admin/posts/edit/@{{d.id}}" lay-event="edit">编辑</a>--}}
                    <a  class="layui-btn layui-btn-danger layui-btn-sm ajax-del" href="{{route('admin.posts.restore')}}" data-id="@{{d.id}}" >恢复</a>
                </div>
            </script>
        </div>
    </div>
@endsection

@section('script')
    <script>
        layui.use(['table','form','layer','jquery'], function(){
            var $ = layui.jquery,
                table = layui.table;
            var dataTable = table.render({
                elem: '#dataTable'
                ,url: "{{ route('admin.posts.data') }}" //数据接口
                ,where: {recycle: 1}
                ,page: true //开启分页
                ,cols: [[ //表头
                    {checkbox: true,fixed: true}
                    ,{field: 'id', title: 'ID', sort: true,width:80}
                    ,{field: 'post_title', title: '名称'}
                    ,{field: 'many_category', width: 240, title: '所属分类',templet:function(data){
                        console.log(data.many_category);
                        var html='';
                        if(data.many_category.length>0){
                            $.each(data.many_category,function(i,j){
                                html = html + " | "+ j.title;
                            });
                            html=html.substr(2);
                            return html;
                        }
                        return html;
                    }}
                    ,{field: 'post_thumb', title: '缩略图'}
                    ,{field: 'post_status', title: '状态'}
                    ,{fixed: 'right',  align:'center', toolbar: '#options'}
                ]]
            });
        });
    </script>
@endsection